/*
 * Copyright (C) 2011 Johan Kannala
 *
 * Licensed under the MIT License. You can find a copy of the License at in the
 * license.txt file.
 */
package com.joppe.vocabtutor;

import android.content.Context;
import android.database.Cursor;
import android.view.*;
import android.widget.*;

/**
 * @author joppe
 * 
 */
public class BookListCursorListAdapter extends CursorAdapter {

    /**
     * @param context
     * @param c
     */
    public BookListCursorListAdapter(Context context, Cursor c) {
        super(context, c);
    }

    /*
     * (non-Javadoc)
     * 
     * @see android.widget.CursorAdapter#bindView(android.view.View,
     * android.content.Context, android.database.Cursor)
     */
    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        TextView bookTitle = (TextView) view.findViewById(R.id.book_title);
        bookTitle.setText(cursor.getString(1));
        TextView bookDetails = (TextView) view.findViewById(R.id.book_details);
        bookDetails.setText(cursor.getInt(2) + " chapters " + cursor.getInt(3)
                + " words");
    }

    /*
     * (non-Javadoc)
     * 
     * @see android.widget.CursorAdapter#newView(android.content.Context,
     * android.database.Cursor, android.view.ViewGroup)
     */
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View bookRow = inflater.inflate(R.layout.book_entry, parent, false);
        bindView(bookRow, context, cursor);
        return bookRow;
    }
}
